package com.dk.controller;

import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.entity.TValuationDTO;
import com.dk.service.ITValuationService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping({"valuationCotroller"})
@Api("线上估值")
public class ValuationController {
    @Autowired
    private ITValuationService itValuationService;


    //线上估值
    @ApiOperation("估值服务")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "tValuation",value = "估值实体类",required = true,paramType = "body")
//    })
    @PostMapping
    public Result<BigDecimal> getvaluationPrice(@RequestParam Integer mileage,@RequestParam Integer damage,@RequestParam BigDecimal price,@RequestParam String statedate) {
//        //从dto中去除车辆原价
//        BigDecimal price = tValuation.getPrice();
//        //从dto中去出上牌时间
//        Date statedate = tValuation.getStatedate();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = null;
        try {
            parse = dateFormat.parse(statedate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        TValuationDTO tValuation = new TValuationDTO();
        tValuation.setDamage(damage);
        tValuation.setMileage(mileage);
        BigDecimal vprice = itValuationService.getvaluationPrice(tValuation,price,parse);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(vprice);
    }
}
